package cn.liu;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class ReceiveHandler {
    //监听elmai队列
    @RabbitListener(queues = {RabbitMQConfig.NAME_QUEUE_EMAIL_1010})
    public void receive_email(String msg, Message message, Channel channel) throws IOException {
        System.out.println("emialHandler收到消息msg："+msg);
        System.out.println("emialHandler收到消息message.getBody："+new String(message.getBody()));
        System.out.println("emialHandler收到消息ConsumerTag："+message.getMessageProperties().getConsumerTag());
        System.out.println("emialHandler收到消息MessageId："+message.getMessageProperties().getMessageId());
        System.out.println("emialHandler收到消息ReceivedExchange："+message.getMessageProperties().getReceivedExchange());
        System.out.println("emialHandler收到消息RoutingKey："+message.getMessageProperties().getReceivedRoutingKey());
        //重要
        System.out.println("emialHandler收到消息DeliveryTag："+message.getMessageProperties().getDeliveryTag());

        //触发手动签收
        //触发手动签收
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }

    //短信消费
    @RabbitListener(queues = RabbitMQConfig.NAME_QUEUE_SMS_1010)
    public void smsHandler(String msg, Message message, Channel channel) throws IOException {
        System.out.println("smsHandler收到消息msg："+msg);
        System.out.println("smsHandler收到消息message.getBody："+new String(message.getBody()));
        System.out.println("smsHandler收到消息ConsumerTag："+message.getMessageProperties().getConsumerTag());
        System.out.println("smsHandler收到消息MessageId："+message.getMessageProperties().getMessageId());
        System.out.println("smsHandler收到消息ReceivedExchange："+message.getMessageProperties().getReceivedExchange());
        System.out.println("smsHandler收到消息RoutingKey："+message.getMessageProperties().getReceivedRoutingKey());
        //重要
        System.out.println("smsHandler收到消息DeliveryTag："+message.getMessageProperties().getDeliveryTag());
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }
} 